<?php
require_once("header.php");
require_once("model/DB.php");
require_once("model/Course.php");
require_once("model/Class.php");
require_once("model/User.php");
require_once("function/admin.login.php");

$class_id = $_GET['id'];
$cs = Course::getCs($class_id);
$class = Classes::getClassById($class_id);
$teacher = User::getUser('id',$class['teacher_id']);

$title = $class['title'];
$name = $teacher[0]['username'];
foreach($cs as $key=>$s){
	if($s['lesson']==1){
		$c1 = $cs[$key];
	}elseif($s['lesson']==2){
		$c2 = $cs[$key];
	}elseif($s['lesson']==3){
		$c3 = $cs[$key];
	}elseif($s['lesson']==4){
		$c4 = $cs[$key];
	}
}
$courses = Course::getcourse();
?>
<script>
$(document).ready(function(){
	$(".lesson").change(function(){
		var id = $(this).attr("id");
		var value = $(this).val();
		var array = id.split("-");
		var lesson = array[0];
		var day = array[1];
		var Class = $("#class_id").val();
		$.post(
			"function/editCs.php",
			{Class:Class,lesson:lesson,day:day,value:value}
		)
	});
});
</script>
<center>
<table id="admin_detail" cellspacing="0" cellpadding="0" >
<tr>
<td id="left_bar" style="border-right:1px solid black;text-align:center; width:100px;">

<br>
<a class="admin_left" href="admin.php">Home</a>
<br>
<br>
<a class="admin_left" href="admin.class.php">Back</a>
</td>
<td>
<div id="kid_list">
<span style="margin-left:10px; font-weight:bold;">Class: <?php echo $title; ?> &nbsp; Teacher: <?php echo $name; ?></span>
<table id="cs"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th scope="col">&nbsp;</th>
    <th scope="col">Mon</th>
    <th scope="col">Tus</th>
    <th scope="col">Wen</th>
    <th scope="col">Thr</th>
    <th scope="col">Fri</th>
    <th scope="col">Sat</th>
    <th scope="col">Sun</th>
  </tr>
  <tr>
    <th scope="row">9:00-9:45</th>
	<?php 

		for($i=1;$i<=7;$i++): 
		$tag = "d".$i;
	?>
    <td><select id="1-<?php echo $i; ?>" class="lesson" ><option value="">None</option><?php  foreach($courses as $course): ?><option value="<?php echo $course['id']; ?>" <?php if($c1[$tag]==$course['id']): ?> selected <?php endif; ?> ><?php echo $course['title']; ?></option><?php endforeach; ?></select></td>
	<?php endfor; ?>
  </tr>
  <tr class="break">
    <th scope="row">9:45-10:15</th>
    <td colspan="7" >Break</td>
  </tr>
  <tr>
    <th scope="row">10:15-11:00</th>
	<?php 

		for($i=1;$i<=7;$i++): 
	?>
    <td><select id="2-<?php echo $i; ?>" class="lesson" ><option value="">None</option><?php $tag = "d".$i; foreach($courses as $course): ?><option value="<?php echo $course['id']; ?>" <?php if($c2[$tag]==$course['id']): ?> selected <?php endif; ?> ><?php echo $course['title']; ?></option><?php endforeach; ?></select></td>
	<?php endfor; ?>
  </tr>
  <tr id="lunch">
  <th scope="row">11:00-15:00</th>
   <td colspan="8">Lunch & Siesta</td>
  </tr>
  <tr>
    <th scope="row">15:00-15:45</th>
	<?php 

		for($i=1;$i<=7;$i++): 
	?>
    <td><select id="3-<?php echo $i; ?>" class="lesson" ><option value="">None</option><?php $tag = "d".$i; foreach($courses as $course): ?><option value="<?php echo $course['id']; ?>" <?php if($c3[$tag]==$course['id']): ?> selected <?php endif; ?> ><?php echo $course['title']; ?></option><?php endforeach; ?></select></td>
	<?php endfor; ?>
  </tr>
  <tr class="break">
    <th scope="row" >15:45-16:15</th>
    <td colspan="7">Break</td>
  </tr>
  <tr>
    <th scope="row">16:15-17:00</th>
	<?php 

		for($i=1;$i<=7;$i++): 
	?>
    <td><select id="4-<?php echo $i; ?>" class="lesson" ><option value="">None</option><?php $tag = "d".$i; foreach($courses as $course): ?><option value="<?php echo $course['id']; ?>" <?php if($c4[$tag]==$course['id']): ?> selected <?php endif; ?> ><?php echo $course['title']; ?></option><?php endforeach; ?></select></td>
	<?php endfor; ?>
  </tr>
</table>
<input type="hidden" value="<?php echo $class_id ?>" id="class_id">
</div>


</td>
</tr>
</table>
</center>